package com.zjy.controller;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zjy.pojo.Department;
import com.zjy.pojo.Msg;
import com.zjy.service.DeptService;

/**
 * 会被扫描，意味着会被容器实例化，并加入容器
 * 会不会被扫描，要看component-scan
 * @author admin
 *
 */
@Controller
public class DeptController {
	
	@Autowired
	DeptService  deptService;
	
	public DeptService getDeptService() {
		return deptService;
	}

	public void setDeptService(DeptService deptService) {
		this.deptService = deptService;
	}

	@RequestMapping("/insertDept")
	public String insertDept(Department dept) {
		//实现部门的添加
		//调用 service 的插入数据
		deptService.insert(dept);
	
		return "success";
	}
	
	@RequestMapping("/index")
	public String index() {
		return "list";
	}
	
	@RequestMapping("/depts")
	@ResponseBody
	public Msg getDepts() {
		//查出所有部门信息
		List<Department> list=deptService.getDepts();
		return Msg.success().add("depts", list);
	}

}
